<template>
	<view class="experience">
		<view class="module-name">
			<span class="name">项目名称</span>
			<span style="margin-right: 10rpx;">:</span>
			<input type="number" placeholder="请输入项目名称" v-model="name" />
		</view>
		<view class="module-name">
			<span class="name">开工时间</span>
			<span style="margin-right: 10rpx;">:</span>
			<input @click="onShowDatePicker('startTime')" type="text" placeholder="请选择开工时间" :vaule="startTime" />
			<mx-date-picker :show="startShowPicker" :type="rangeTime" :value="vaule" :show-tips="true"
			  :show-seconds="true" @confirm="onSelected('startTime')" @cancel="onSelected('startTime')" />
		</view>
		<view class="module-name">
			<span class="name">完工时间</span>
			<span style="margin-right: 10rpx;">:</span>
			<input @click="onShowDatePicker('endTime')" type="text" placeholder="请选择完工时间" v-model="endTime"/>
			<mx-date-picker :show="endShowPicker" :type="rangeTime" :value="vaule" :show-tips="true"
			  :show-seconds="true" @confirm="onSelected(e,'endTime')" @cancel="onSelected(e,'endTime')" />
		</view>
		<view class="module-name">
			<span class="name">所在地区</span>
			<span style="margin-right: 10rpx;">:</span>
			<input type="number" placeholder="请选择所在地区" v-model="name"/>
		</view>
		<view class="module-introduce">
			<view class="head">自我介绍</view>
			<textarea @input="numberWords" placeholder="请简要介绍您所从事的行业以及工作经验" v-model="introduce" maxlength="500" class="introduce-text"></textarea>
			<view class="text-num">{{num}}/500</view>
		</view>
		<view class="uploading">
			<imgUpload :imgArr="imgArray" imgCount="6" ref="imgUpload" url="xxx(上传图片的url)"></imgUpload>
			<button type="default" @click="submit">提交</button>
		</view>
		<view class="save">
			<view class="save-message">
				保存资料
			</view>
		</view>
	</view>
</template>

<script>
	import imgUpload from '../../../components/poiuy-uImgUpload/imgUpload.vue';
	import MxDatePicker from "../../../components/mx-datepicker/mx-datepicker.vue";
	export default {
		data() {
			return {
				startShowPicker: false,
				rangeTime: '15:00:12',
				startTime: '',
				vaule: "",
				endShowPicker: false,
				endTime: '',
				num: 0,
				imgArray: [],
				head: [{
					token: "zx6c54asdq89w7eqw6e46ad4"
				}, {
					sign: 's6d5a4dqwe7q9w87a6'
				}], //示范格式 JSON   使用方式header="head"
				config: {
					delIcon: '', //删除图片icon
					resultTip: true, //结果提示
					resultType: '1', //结果展示类型
					loadIcon: '', //加载时的图标
					loadText: '' //加载时的文字
				}

			}
		},
		components: {
			"imgUpload": imgUpload,
			"MxDatePicker": MxDatePicker
		},
		methods: {
			numberWords() {
				this.num = this.introduce.length
			},
			submit() {
				//开始上传图片
				this.$refs.imgUpload.upload(res => {
					if (res.code == 0) {
						//0为正常返回，将回调的线上图片数组 赋值给需要提交的表单里
						//res.urlArray 线上路径图片数组对象
						//TODO
					} else {
						//用户没有上传图片的返回 code码为400
					}

					//可以在下面继续写提交代码
				});
			},
			resultUrl(e) {
				console.log(e);
				//成功默认为0
				if (e.code == 0) {
					this.imgArr.push(e.fileVo.fileUrl);
				}
			},
			delImg(e) {
				this.imgArr.splice(e, 1) //为删除图片数组的下标
			},
			onShowDatePicker(type) { //显示
				debugger
				let date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type == "startTime") {
					this.startShowPicker = true;
				} else {
					this.endShowPicker = true;
				}
				this.vaule = year + "-" + month + "-" + day
			},
			onSelected(e, type) { //选择
			debugger
				if (type == "startTime") {
					this.startShowPicker = false;
				} else {
					this.endShowPicker = false;
				}
				this.startShowPicker = false;
				if (e) {
					if (type == "startTime") {
						this.startTime = e.value;
					} else {
						this.endTime = e.value;
					}
					//选择的值
					console.log('value => ' + e.value);
					//原始的Date对象
					console.log('date => ' + e.date);
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.experience {
		background: #cecece;
		position: relative;

		.module-name {
			width: 100vw;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			padding: 20rpx 0 20rpx 20rpx;
			border-bottom: solid 1px #d8d8d8;
			background: #FFFFFF;
			margin-bottom: 20rpx;

			.name {
				display: inline-block;
				width: 160rpx;
				text-align-last: justify;
			}
		}

		.module-introduce {
			background: #FFFFFF;
			padding: 20rpx;
			font-size: 30rpx;
			border: solid 1px #a1a1a1;
			position: relative;
			margin-bottom: 20rpx;

			.introduce-text {
				margin-top: 20rpx;
				margin-bottom: 120rpx;
			}

			.text-num {
				position: absolute;
				right: 40rpx;
				top: 376rpx;
			}
		}

		.save {
			width: 100vw;
			text-align: center;
			position: fixed;
			bottom: 0;
			right: -6rpx;
			background: #cecece;
			padding: 20rpx 30rpx;

			.save-message {
				width: 90vw;
				background: #007AFF;
				color: #FFFFFF;
				font-size: 32rpx;
				padding: 14rpx 120rpx;
				border-radius: 16rpx;
			}
		}

		.uploading {
			background: #FFFFFF;
			margin-bottom: 50rpx;
		}
	}
</style>
